<route lang="json5" type="page">
{
  layout: 'default',
  style: {
    navigationBarTitleText: '巡检单详情',
  },
}
</route>

<template>
  <view class="px-3 pt-3 pb-safe">
    <view v-show="!loading" class="p-3 bg-white rounded-4 overflow-hidden">
      <view class="leading-relaxed text-sm">
        <view class="flex mt-1">
          <view class="flex">
            <view class="w-25 text-[#6e6e6e] flex items-center shrink-0">
              路线名称
              <wd-tag type="warning" class="ml-2">智</wd-tag>
            </view>
          </view>
          {{ insDetail.roadMapName }}
        </view>
        <view class="flex mt-1">
          <view class="w-25 text-[#6e6e6e]">巡检类别</view>
          {{ patrolTypeMap[insDetail.patrolType] }}
        </view>
        <view class="flex mt-1">
          <view class="w-25 text-[#6e6e6e]">项目名称</view>
          {{ insDetail.projectName }}
        </view>
        <view class="flex mt-1">
          <view class="w-25 text-[#6e6e6e] shrink-0">起止日期</view>
          {{ insDetail.startTime }}
          - {{ insDetail.endTime }}
        </view>
        <view class="flex mt-1">
          <view class="w-25 text-[#6e6e6e] shrink-0">执行人</view>
          刘伟
        </view>
        <view class="flex mt-1">
          <view class="w-25 text-[#6e6e6e]">总点位数</view>
          {{ insDetail.points }}
        </view>
        <view class="flex mt-1">
          <view class="w-25 text-[#6e6e6e]">已巡检点位数</view>
          {{ insDetail.completePoints }}
        </view>
      </view>
    </view>

    <view class="pb-20">
      <view
        class="p-3 bg-white rounded-4 overflow-hidden mt-3 text-sm"
        v-for="item in taskList"
        :key="item.id"
        @click="handlePointDetail(item)"
      >
        <view class="flex items-center justify-between">
          <view class="center">
            <image :src="inspectionPointIcon" class="w-4 h-4 mr-2" mode="scaleToFill" />
            {{ item.pointName }}
          </view>
          <wd-icon name="arrow-right" size="22px" color="#ccc"></wd-icon>
        </view>

        <view>
          <view class="flex justify-between py-2">
            <text>编号： {{ item.pointNumber }}</text>
            <text>
              顺路任务：
              <text class="font-bold">{{ item.pointContentCount }}</text>
              项
            </text>
          </view>
        </view>

        <view class="flex justify-between leading-relaxed text-[#6e6e6e]">
          <view class="flex flex-col text-center">
            <view>执行人</view>
            <view>{{ item.ponitExecuter }}</view>
          </view>
          <view class="flex flex-col text-center">
            <view>执行时间</view>
            <view>{{ item.pointExecuteTime }}</view>
          </view>
          <view class="flex flex-col text-center">
            <view>执行状态</view>
            <view>
              <wd-text
                type="primary"
                size="14px"
                :text="patrolStatusMap[item.pointExecuteStatus]"
              ></wd-text>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="fixed bottom-0 left-0 w-screen px-4 pb-safe bg-white">
      <view class="py-3 flex justify-around">
        <wd-button class="w-40vw">漏检结束</wd-button>
        <wd-button class="w-40vw" type="warning">转单</wd-button>
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
import inspectionPointIcon from './static/inspection-point.svg'
import { inspectDetail, listByTask } from './api/index'
import { onLoad } from '@dcloudio/uni-app'
import { patrolTypeMap, patrolStatusMap } from './dict'

const loading = ref(true)
const insnId = ref('')
const insDetail = ref<any>({})
onLoad(async (options) => {
  insnId.value = options.id
  getInspectDetail()

  getListByTask()
})

async function getInspectDetail() {
  try {
    loading.value = true
    const { data } = await inspectDetail(insnId.value)
    insDetail.value = data
    loading.value = false
  } catch (error) {}
}

const taskList = ref([])
async function getListByTask() {
  try {
    const { rows } = await listByTask(insnId.value)
    taskList.value = rows.filter((item) => item !== null)
  } catch (error) {}
}

function handlePointDetail(item) {
  uni.navigateTo({
    url: `/pages-sub/inspection/processing?id=${item.id}`,
  })
}
</script>

<style lang="scss" scoped>
//
</style>
